<%@page import="HumanM.PUser"%>
<%@page import="jdbc.DBOUser"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户注册处理页面</title>
</head>
<body>
<%
    PUser user1=new PUser();
    DBOUser dbu=new DBOUser();
	request.setCharacterEncoding("UTF-8");
	String password1= request.getParameter("password1");
	String password2= request.getParameter("password1");
	
	user1.puser_name=request.getParameter("username");
	user1.puser_password=password1;
	user1.puser_Email=request.getParameter("email");
	user1.puser_tel=request.getParameter("tel");
	user1.puser_birthday=new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("birthday"));
	user1.puser_password_q=request.getParameter("question");
	user1.puser_password_a=request.getParameter("reply");
	user1.puser_sex=request.getParameter("sex");
	PUser user=new PUser(user1.puser_name,user1.puser_password,user1.puser_sex,user1.puser_birthday,user1.puser_tel,user1.puser_Email,user1.puser_password_a,user1.puser_password_q);
	
	//out.print(user.puser_name+user.puser_password+user.puser_Email+user.puser_tel+user.puser_birthday);
	//out.print(user.puser_password_q+user.puser_password_a+user.puser_sex);

	if(user.puser_name==""||user.puser_password=="")
	{
		out.print("<script>alert('请输入用户名或密码！');window.location='user_reg.jsp'</script>");
	}
	else if(password1!=password2)
	{
		out.print("<script>alert('两次密码输入不一致！请重新输入！');window.location='user_reg.jsp'</script>");
	}
	else  if(dbu.is_user_exist(user.puser_name))
   {
	   out.print("<script>alert('用户名已存在，请重试！');window.location='user_reg.jsp'</script>");
   }
	else if(user.puser_sex=="")
     {
  	   out.print("<script>alert('请选择性别！');window.location='user_reg.jsp'</script>");
     }
	else if(dbu.SignUp_user(user))
	  {
	   out.print("<script>alert('注册成功！你个小辣鸡！登陆吧！');window.location='User_login.jsp'</script>");
	 }else{
	   
	   out.print("<script>alert('添加信息异常！注册失败！');window.location='user_reg.jsp'</script>");
	 }
   
 %>




</body>
</html>